/**
 * 
 */
package com.vivid.dynamics.oknow.model;

import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author jason
 * created at:: Jul 27, 2011 5:07:19 PM
 */
public class UserTheme {
	private int id;
	private String name;
	private String descr;
	private String uri;
	private String backgroundPic;
	private Set<User> users;

	/**
	 * ctor.
	 */
	protected UserTheme() {}
	
	/**
	 * ctor.
	 * @param name
	 * @param desc
	 * @param uri
	 * @param backgroundPic
	 */
	public UserTheme(String name, String descr, String uri, String backgroundPic) {
		super();
		this.name = name;
		this.descr = descr;
		this.uri = uri;
		this.backgroundPic = backgroundPic;
	}

	/**
	 * <b>PS</b>. a MUST for hibernate entities, or you will have problems 
	 * during association methods; simply you can't remove / update the correct
	 * logical Entity in your collections<p/>
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		/*
		result = prime * result
				+ ((backgroundPic == null) ? 0 : backgroundPic.hashCode());
		result = prime * result + ((descr == null) ? 0 : descr.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((uri == null) ? 0 : uri.hashCode());*/
		return result;
	}

	/**
	 * <b>PS</b>. a MUST for hibernate entities, or you will have problems 
	 * during association methods; simply you can't remove / update the correct
	 * logical Entity in your collections<p/>
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserTheme other = (UserTheme) obj;
		if (backgroundPic == null) {
			if (other.backgroundPic != null)
				return false;
		} else if (!backgroundPic.equals(other.backgroundPic))
			return false;
		if (descr == null) {
			if (other.descr != null)
				return false;
		} else if (!descr.equals(other.descr))
			return false;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (uri == null) {
			if (other.uri != null)
				return false;
		} else if (!uri.equals(other.uri))
			return false;
		return true;
	}

	/**
	 * 
	 */
	@Override
	public String toString() {
		return "UserTheme [id=" + id + ", name=" + name + ", descr=" + descr
			+ ", uri=" + uri + ", backgroundPic=" + backgroundPic + "]";
	}

	/* ********************** */
	/* *  accessor/mutator  * */
	/* ********************** */
	
	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:09:25 PM
	 */
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:09:30 PM
	 */
	public String getDescr() {
		return descr;
	}
	public void setDescr(String descr) {
		this.descr = descr;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:09:36 PM
	 */
	public String getUri() {
		return uri;
	}
	public void setUri(String uri) {
		this.uri = uri;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:09:40 PM
	 */
	public String getBackgroundPic() {
		return backgroundPic;
	}
	public void setBackgroundPic(String backgroundPic) {
		this.backgroundPic = backgroundPic;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:09:45 PM
	 */
	public int getId() {
		return id;
	}
	protected void setId(int pId) {
		this.id=pId;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Aug 3, 2011  2:06:36 PM
	 */
	public Set<User> getUsers() {
		if (this.users==null) {
			this.users=new HashSet<User>();
		}
		return users;
	}
	protected void setUsers(Set<User> users) {
		this.users = users;
	}
	
	/* ********************************* */
	/* *     association method(s)     * */
	/* ********************************* */

	/**
	 * convenient method to add a User to the UserTheme's set
	 * @param pUser
	 * @author jason
	 * created at:: Aug 3, 2011  3:13:18 PM
	 */
	public void addUser(final User pUser) {
		if (pUser!=null) {
			// update "this"
			this.getUsers().add(pUser);
			
			// update the "user"
			pUser.setUserTheme(this);
		}
	}
	
	/**
	 * convenient method to remove a User from the UserTheme's set
	 * @param pUser
	 * @author jason
	 * created at:: Aug 3, 2011  3:17:44 PM
	 */
	public void removeUser(final User pUser) {
		if (pUser!=null) {
			// update "this"
			this.getUsers().remove(pUser);
			
			// update the "user"
			pUser.setUserTheme(null);
		}
	}
	
}
